package com.cloudsigns.factorymanager2.project.customview;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;

/**
 * Created by tony on 2017/12/2.
 */

public class WorkSheetLevelPopupWindow extends PopupWindow {
    private View conentView;
    private TextView tv_first_level, tv_second_lever, tv_third_level, tv_firth_lever;
    private View.OnClickListener mClickListener;


    public WorkSheetLevelPopupWindow(final Activity context) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.popupwindow_worksheet_lever, null);
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        // this.setAnimationStyle(R.style.AnimationPreview);


        tv_first_level = conentView.findViewById(R.id.tv_first_level);
        tv_second_lever = conentView.findViewById(R.id.tv_second_lever);
        tv_third_level = conentView.findViewById(R.id.tv_third_level);
        tv_firth_lever = conentView.findViewById(R.id.tv_firth_lever);


    }


    /**
     * 显示popupWindow
     *
     * @param anchor
     */
    public void showPopupWindow(View anchor) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(anchor, anchor.getLayoutParams().width / 2, 5);// 显示popupwindow的位�?
        } else {
            this.dismiss();
        }
    }

    public void setCusOnDismissListener(PopupWindow.OnDismissListener dismissListener) {

        setOnDismissListener(dismissListener);
    }

    public void setOnClickListener(View.OnClickListener mClickListener) {
        this.mClickListener = mClickListener;

        tv_first_level.setOnClickListener(mClickListener);
        tv_second_lever.setOnClickListener(mClickListener);
        tv_third_level.setOnClickListener(mClickListener);
        tv_firth_lever.setOnClickListener(mClickListener);

    }
}
